package me.zhanshi123.vipstorage.util;

public class StorageData {
    private int id;
    private String player;
    private String vip;
    private long seconds;
    private long activate;

    public StorageData(int id, String player, String vip, long seconds, long activate) {
        this.id = id;
        this.player = player;
        this.vip = vip;
        this.seconds = seconds;
        this.activate = activate;
    }

    public StorageData(String player, String vip, long seconds, long activate) {
        this.player = player;
        this.vip = vip;
        this.seconds = seconds;
        this.activate = activate;
    }

    public long getActivate() {
        return activate;
    }

    public void setActivate(long activate) {
        this.activate = activate;
    }

    public String getLastGroup() {
        int hashmark = vip.indexOf('#');
        String lastGroup = vip.substring(hashmark + 1, vip.length());
        return lastGroup;
    }

    public String getGroup() {
        int hashmark = vip.indexOf('#');
        String lastGroup = vip.substring(0, hashmark);
        return lastGroup;
    }

    public long getLastSeconds() {
        long now = System.currentTimeMillis();
        long last = seconds * 1000;
        return (activate + last - now) / 1000;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPlayer() {
        return player;
    }

    public void setPlayer(String player) {
        this.player = player;
    }

    public String getVip() {
        return vip;
    }

    public void setVip(String vip) {
        this.vip = vip;
    }

    public long getSeconds() {
        return seconds;
    }

    public void setSeconds(long seconds) {
        this.seconds = seconds;
    }

    public boolean isValid() {
        long activate = this.activate;
        long last = seconds * 1000;
        return activate + last >= System.currentTimeMillis();
    }

    @Override
    public String toString() {
        return "StorageData{" +
                "id=" + id +
                ", player='" + player + '\'' +
                ", vip='" + vip + '\'' +
                ", seconds=" + seconds +
                ", activate=" + activate +
                '}';
    }
}
